import sqlite3
import pandas as pd

def import_excel_to_sqlite(excel_file_path):
    # 连接到 SQLite 数据库
    conn = sqlite3.connect('example.db')
    c = conn.cursor()

    # 读取 Excel 文件
    df = pd.read_excel(excel_file_path)

    # 遍历 DataFrame 中的每一行
    for index, row in df.iterrows():
        chinese = row[0]
        hiragana = row[1]
        category = row[2]
        meaning = ""  # 由于没有第四列数据，含义字段使用空字符串填充

        # 插入数据到 words 表
        c.execute('INSERT INTO words (chinese, hiragana, category, meaning) VALUES (?, ?, ?, ?)', (chinese, hiragana, category, meaning))

    # 提交更改并关闭连接
    conn.commit()
    conn.close()
    print("数据导入成功！")

if __name__ == "__main__":
    # 请将 <username> 替换为你的 Windows 用户名
    excel_file_path = "C:\\Users\\Jacy\\Desktop\\words.xlsx"
    import_excel_to_sqlite(excel_file_path)